﻿
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace demo
{
    public class 圆弧加厚
    {

        public static void Test(ExternalCommandData commandData)
        {
            var doc = commandData.Application.ActiveUIDocument.Document;

            Curve curve = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 10, 0));

            var s1 = new XYZ(-5, 0, 0);
            var s2 = new XYZ(5, 0, 0);
            var s3 = new XYZ(0, 5, 0);

            Arc ar1 = Arc.Create(s1,s2,s3);

            var l = Line.CreateBound(new XYZ(5,0,0), new XYZ(-5, 0, 0));
          

            CurveLoop loop = new CurveLoop();
            loop.Append(ar1);
            loop.Append(l);
            var profile0 = new Profile(loop);

            var newLoop = CurveLoop.CreateViaOffset(loop, -0.5, new XYZ(0, 0, 1));


            var profile = new  Profile(newLoop);

            CurveLoop path = new CurveLoop();
            path.Append(curve);

            Solid solid1 = profile.CreateSweptGeometry(path, new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId));

            Solid solid0 = profile0.CreateSweptGeometry(path, new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId));

            var  solid= BooleanOperationsUtils.ExecuteBooleanOperation(solid1, solid0, BooleanOperationsType.Difference);

            using (Transaction transaction = new Transaction(doc, "tCreateAndStore"))
            {
                transaction.Start();

                CreateShape(doc, new List<GeometryObject>() { solid });
                transaction.Commit();
            }

        }


      


        private static void CreateShape(Document document, List<GeometryObject> geometries)
        {
            Category category = Category.GetCategory(document, BuiltInCategory.OST_GenericModel);
            DirectShape shape = DirectShape.CreateElement(document, category.Id);
            shape.SetShape(geometries);
        }

    }
}
